<html>
 <head>
  <title>WaveDrom Editor</title>
  <link rel="shortcut icon" href="images/favicon.ico"/>
  <meta http-equiv="refresh" content="1; url=http://wavedrom.com/editor.html" />
  <!-- <link href='http://fonts.googleapis.com/css?family=Ubuntu+Mono' rel='stylesheet' type='text/css'>
  <link rel="stylesheet" href="css/codemirror.css">
  <link rel="stylesheet" href="css/dialog.css">
  <link rel="stylesheet" href="css/main.css">

  <script type="text/javascript" src="scripts/codemirror-compressed.js"></script>
  <script type="text/javascript" src="skins/default.js"></script>
  <script type="text/javascript" src="skins/narrow.js"></script>
  <script type="text/javascript" src="WaveDrom.js"></script>

  <script>
    function editorState (op) {
        "use strict";
        var rot, drot, per, dper, sizeTXT, sizeSVG, styleTXT, styleSVG;

        function delta (root, name) {
            "use strict";
            if (root && root[name]) {
                var res = Number (root[name]);
                if ((res !== 1) && (res !== -1)) { return 0; }
                return res;
            }
            return 0;
        }
        function ring (name, delta, size, init) {
            "use strict";
            var res;
            res = parseInt (localStorage [name]);
            if (res || res === 0) {
                res += delta;
                if (res >= size) {
                    res -= size;
                } else if (res < 0) {
                    res += size;
                }
            } else {
                res = init;
            }
            localStorage [name] = res;
            return res;
        }
        function setStyle (id, prop) {
            "use strict";
            var e = document.getElementById (id);
            e.removeAttribute("style");
            for (var p in prop) {
                e.style [p] = prop [p];
            }
        }
        drot = delta (op, 'rot');
        dper = delta (op, 'per');
        rot  = ring  ('drom.editor.rot', drot, 4, 0);
        per  = ring  ('drom.editor.per', dper, 7, 3);
        sizeTXT = ((per + 2) * 10) + '%';
        sizeSVG = ((8 - per) * 10) + '%';

        if (rot === 1) {        // SVG|TXT
            styleSVG = {width: sizeSVG, height: '100%', cssFloat: 'left', overflow: 'hidden'};
            styleTXT = {                height: '100%'};
        } else if (rot === 2) { // SVG/TXT
            styleSVG = {width: '100%', height: sizeSVG, overflow: 'hidden'};
            styleTXT = {height: sizeTXT};
        } else if (rot === 3) { // TXT|SVG
            styleSVG = {width: sizeSVG, height: '100%', cssFloat: 'right', overflow: 'hidden'};
            styleTXT = {width: sizeTXT, height: '100%'};
        } else {                // TXT/SVG
            styleSVG = {width: '100%', height: sizeSVG, position: 'absolute', bottom: 0, overflow: 'hidden'};
            styleTXT = {height: sizeTXT};
        }
        setStyle('SVG', styleSVG);
        setStyle('TXT', styleTXT);
        WaveDrom.EditorRefresh();
    }
    function editorInit () {
        "use strict";
        if (document.location.search) {
          cm.setValue(decodeURIComponent(window.location.search.substr(1)));
//          document.getElementById ('InputJSON_0').value = decodeURIComponent(window.location.search.substr(1));
        }
        editorState ();
    }
    function setFullURL () {
        "use strict";
        document.location.search = encodeURIComponent(document.getElementById ('InputJSON_0').value);
    }
  </script>
 </head>

  <body onload="editorInit()">
    <div id="content">
      <div class="toolbar">
        <img class="button" title="rotate layout" src="images/ic_rot.png" onclick="editorState({rot:1})"/>

        <img class="button" title="change proportions" src="images/ic_persent.png" onclick="editorState({per:1})"/>

        <a id="download_svg" href="data:image/svg+xml,<xml>" download="mywave.svg">
          <img class="button" title="Save SVG file" src="images/ic_download_svg.png"/>
        </a>

        <a id="download_json" href="data:text/plain,{}" download="mywave.json">
          <img class="button" title="Save JSON file" src="images/ic_download_json.png"/>
        </a>

        <img class="button" title="expand full URL" src="images/ic_url.png" onclick="setFullURL()"/>

        <a href="http://wavedrom.googlecode.com/svn/trunk/tutorial.html"><img class="button" title="Guide to the WaveDrom" src="images/ic_guide.png"/></a>

        <a href="http://wavedrom.googlecode.com"><img class="button" title="Powered by WaveDrom v.2013.12.17" src="images/ic_logo.png"/></a>
      </div>
      <div id='SVG'><div id="WaveDrom_Display_0"></div></div>
      <div id='TXT'><textarea id="InputJSON_0"></textarea></div>
    </div>
  <script type="text/javascript">
    (function KillBill () {
      if (navigator.appName.indexOf('Explorer') >= 0) {
        var e = document.getElementById('content');
        e.parentNode.removeChild(e);
        document.write("<h1>Sorry, Internet Explorer is not supported.</h1>");
        document.body.style.backgroundColor = '#ffdddd';
        window.stop();
      }
    })();
  </script>
  <script>
    var e, val, timer;
    e = document.getElementById ('InputJSON_0');
    val = localStorage ['waveform'];
    if (val === undefined || val === '') {
        val = "{signal: [\n  {name: 'clk', wave: 'p.....|...'},\n  {name: 'dat', wave: 'x.345x|=.x', data: ['head', 'body', 'tail', 'data']},\n  {name: 'req', wave: '0.1..0|1.0'},\n  {},\n  {name: 'ack', wave: '1.....|01.'}\n]}\n";
        localStorage ['waveform'] = val;
    }
    e.value = val;
    var cm = CodeMirror.fromTextArea (e, {lineNumbers: true, mode: {name: 'javascript', json: true}, matchBrackets: true, autoCloseBrackets: true, highlightSelectionMatche: true, autofocus: true});
    cm.on ("change", function (cm, change) {
        function c () {
            var v = cm.getValue();
            e.value = v;
            localStorage ['waveform'] = v;
            WaveDrom.EditorRefresh ();
        }
        timer = setTimeout (c, 750);
    });
  </script> -->
  <script type="text/javascript">
    window.location.href = "http://wavedrom.com/editor.html"
  </script>
  <script type="text/javascript">
    var _gaq = _gaq || [];
    _gaq.push(['_setAccount', 'UA-21660728-1']);
    _gaq.push(['_setDomainName', 'wavedrom.googlecode.com']);
    _gaq.push(['_trackPageview']);
    (function() {
      var ga = document.createElement('script'); ga.type = 'text/javascript'; ga.async = true;
      ga.src = ('https:' == document.location.protocol ? 'https://ssl' : 'http://www') + '.google-analytics.com/ga.js';
      var s = document.getElementsByTagName('script')[0]; s.parentNode.insertBefore(ga, s);
    })();
  </script>
</body>
</html>
